﻿namespace Jhong.FunMVC.Razor
{
    using Westwind.RazorHosting;

    public static class InputExtension
    {
        public static RawString TextBox(this RazorHTMLHelper helper, string name)
        {
            return helper.TextBox(name, null);
        }

        public static RawString TextBox(this RazorHTMLHelper helper, string name, object value)
        {
            return helper.TextBox(name, value, null);
        }

        public static RawString TextBox(this RazorHTMLHelper helper, string name, object value, object htmlAttributes)
        {
            var tb = @"<input type='text' name='{0}' id='{0}' value='{1}' {2} />";
            return new RawString(string.Format(tb, name, value, helper.AnonymousObjectToHtmlString(htmlAttributes)));
        }

        public static RawString RadioButton(this RazorHTMLHelper helper, string name, object value)
        {
            return helper.RadioButton(name, value, false, null);
        }

        public static RawString RadioButton(this RazorHTMLHelper helper, string name, object value, bool isChecked)
        {
            return helper.RadioButton(name, value, isChecked, null);
        }

        public static RawString RadioButton(this RazorHTMLHelper helper, string name, object value, object htmlAttributes)
        {
            return helper.RadioButton(name, value, false, htmlAttributes);
        }

        public static RawString RadioButton(this RazorHTMLHelper helper, string name, object value, bool isChecked, object htmlAttributes)
        {
            var rb = @"<input type='radio' name='{0}' id='{0}' value='{1}' {2} {3} />";
            return new RawString(string.Format(rb, name, value, isChecked ? "checked='checked'" : string.Empty, helper.AnonymousObjectToHtmlString(htmlAttributes)));
        }

        public static RawString Password(this RazorHTMLHelper helper, string name)
        {
            return helper.Password(name, null);
        }

        public static RawString Password(this RazorHTMLHelper helper, string name, object value)
        {
            return helper.Password(name, value, null);
        }

        public static RawString Password(this RazorHTMLHelper helper, string name, object value, object htmlAttributes)
        {
            var pwd = @"<input type='password' name='{0}' id='{0}' value='{1}' {2} />";
            return new RawString(string.Format(pwd, name, value, helper.AnonymousObjectToHtmlString(htmlAttributes)));
        }

        public static RawString Hidden(this RazorHTMLHelper helper, string name)
        {
            return helper.Hidden(name, null);
        }

        public static RawString Hidden(this RazorHTMLHelper helper, string name, object value)
        {
            return helper.Hidden(name, value, null);
        }

        public static RawString Hidden(this RazorHTMLHelper helper, string name, object value, object htmlAttributes)
        {
            var hid = @"<input type='hidden' id='{0}' name='{0}' value='{1}' {2} />";
            return new RawString(string.Format(hid, name, value, helper.AnonymousObjectToHtmlString(htmlAttributes)));
        }

        public static RawString CheckBox(this RazorHTMLHelper helper, string name, bool isChecked, object htmlAttributes)
        {
            var cb = @"<input type='checkbox' name='{0}' id='{0}'  {1} {2}  />";
            return new RawString(string.Format(cb, name, isChecked ? "checked='checked'" : string.Empty, helper.AnonymousObjectToHtmlString(htmlAttributes)));
        }

        public static RawString CheckBox(this RazorHTMLHelper helper, string name)
        {
            return helper.CheckBox(name, false, null);
        }

        public static RawString CheckBox(this RazorHTMLHelper helper, string name, bool isChecked)
        {
            return helper.CheckBox(name, isChecked, null);
        }

        public static RawString CheckBox(this RazorHTMLHelper helper, string name, object htmlAttributes)
        {
            return helper.CheckBox(name, false, htmlAttributes);
        }
    }
}